package com.kll.carolinehmibiz

import android.app.Application
import android.os.Build
import com.kll.carolinehmibiz.model.OperateListener
import com.kll.carolinehmibiz.net.bean.GetAppNewlyVersionResponse


/**
 * ====================================================
 * Created by Ziliang Cai on 2021/12/8 21:01
 * <a href="mailto:752777456@qq.com">Contact me</a>
 * ====================================================
 */
open abstract class BaseApplication: Application() {

    override fun onCreate() {
        super.onCreate()

        OperationManager.getInstancce().init(this)
        AccountManager.getInstancce().init(this)

//         checkAppVersion()
    }

    private fun checkAppVersion() {

        OperationManager.getInstancce().getAppNewlyVersion(object: OperateListener{
            override fun onSuccess(state: Int, obj: Any?) {
                if(obj != null) {
                    val versionInfo = obj as GetAppNewlyVersionResponse
                    val currentVersionCode = 0

                    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
                        packageManager.getPackageInfo(packageName, 0).versionCode
                    } else {
                        packageManager.getPackageInfo(packageName, 0).longVersionCode
                    }

                    if(versionInfo.versioncode > currentVersionCode) {
                        onNewlyVersion(versionInfo)
                    }
                }

            }

            override fun onFail(code: Int, message: String) {
                //
            }

        })
    }

    /**
     * 有新版本提示
     */
    abstract fun onNewlyVersion(versionInfo: GetAppNewlyVersionResponse)
}